package role

import (
	"context"

	"jinrigaoping/api/superadmin/internal/svc"
	"jinrigaoping/api/superadmin/internal/types"
	"jinrigaoping/rpc/sys/sys"

	"github.com/spf13/cast"
	"github.com/zeromicro/go-zero/core/logx"
)

type RoleInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRoleInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleInfoLogic {
	return &RoleInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoleInfoLogic) RoleInfo(req *types.SysRoleInfoReq) (resp *types.SysRoleInfoRes, err error) {

	infoResp, err := l.svcCtx.SysRpc.SysRoleInfo(l.ctx, &sys.SysRoleInfoReq{Id: req.Id})
	if err != nil {
		return nil, err
	}

	return &types.SysRoleInfoRes{
		Id:         infoResp.Id,
		RoleName:   infoResp.RoleName,
		Remark:     infoResp.Remark,
		MenuIdList: cast.ToStringSlice(infoResp.MenuIdList),
	}, nil
}
